local huanhuo = fk.CreateSkill {
  name = "th_huanhuo",
}

huanhuo:addEffect(fk.TargetSpecifying, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(huanhuo.name) and data.card and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and
    data.tos and #data:getAllTargets() == 1 and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local type = data.card:getTypeString()
    local prompt = "#th_huanhuo-invoke:::"
    local targets = data:getExtraTargets({ bypass_distances = false, bypass_times = true })
    if #targets == 0 then
      prompt = "#th_huanhuo-invokeX:::"
    end
    local _, dat = room:askToUseActiveSkill(player, {
      skill_name = "#th_huanhuo_select",
      prompt = prompt .. type,
      cancelable = true,
      extra_data = {
        skillName = huanhuo.name,
        type = type,
        targets = table.map(targets, Util.IdMapper)
      }
    })
    if dat then
      event:setCostData(self, { tos = dat.targets, cards = dat.cards })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local cards, targets = dat.cards, dat.tos
    room:throwCard(cards, huanhuo.name, player, player)
    if #targets ~= 0 then
      room:doIndicate(player.id, targets)
      for _, to in ipairs(targets) do
        data:addTarget(to)
      end
    else
      for _, p in ipairs(room:getAlivePlayers(false)) do
        data:setDisresponsive(p)
      end
    end
  end
})

Fk:loadTranslationTable{
  ["th_huanhuo"] = "幻惑",
  [":th_huanhuo"] = "当你使用基本牌或普通锦囊牌指定唯一目标时，你可以弃置一张：<br>\
  同类型牌：为此牌增加一个目标；<br>\
  不同类型牌：令此牌不可响应。",

  ["#th_huanhuo-invoke"] = "幻惑：你可以弃置一张%arg，令此牌增加一个目标，或弃置一张非%arg，令此牌不可响应",
  ["#th_huanhuo-invokeX"] = "幻惑：你可以弃置一张非%arg，令此牌不可响应",
  ["@th_shishen"] = "式神",
}

return huanhuo